<?php

class Mod_Ad extends CI_Model
{
	function Mod_Ad()
	{
		parent::__construct();
	}

	function login_admin($username,$password){
		$value_user = $this->db->get_where('admins',array('username'=> $username, 'password'=>$password, 'status'=>'1'));
		$_SESSION['admin_login'] = FALSE;	
		
		if ($value_user->num_rows()>0) {				
			$row = $value_user->row_array();
			
			$_SESSION['admin_id']			= $row['id'];
			$_SESSION['admin_login']		= TRUE;
			$_SESSION['username']			= $row['username'];	
			$_SESSION['show']				= 0;
			$_SESSION['error_loginadmin']	= '';		
			
			//thiet lap cookie
			if(!empty($_SESSION['pass_check']) && isset($_SESSION['pass_check'])) {
				setcookie('username',$username,time() + 60); 
				setcookie('password',$password,time() + 60);
			}
			
			redirect('back_end/backend');	
		}else{
			$_SESSION['show']				= 1;
			$_SESSION['admin_id']			= '';
			$_SESSION['admin_login']		= FALSE;
			$_SESSION['username']			= '';
			$_SESSION['error_loginadmin']	= 'Username hoặc Password không hợp lệ!';	
					
			redirect('back_end/login');	
		}
	}
	
	function is_logged_in(){
		if(!isset($_SESSION['admin_login']) || $_SESSION['admin_login'] == FALSE) {
			$_SESSION['error_loginadmin']	= '';	
			redirect('back_end/login');
		}	
	}
}
?>